/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.zipking.cloud.springbootmybatis.service;

import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.StrUtil;

import com.alibaba.fastjson.JSON;
import com.zipking.cloud.springbootmybatis.handle.AbstractPayHandler;
import com.zipking.cloud.springbootmybatis.enums.PayChannelEnum;
import com.zipking.cloud.springbootmybatis.model.PayRequest;
import com.zipking.cloud.springbootmybatis.model.PayResponse;
import com.zipking.cloud.springbootmybatis.enums.PayTradeTypeEnum;
import com.zipking.cloud.springbootmybatis.strategy.AbstractExecuteStrategy;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;

/**
 * 阿里支付组件
 * 公众号：马丁玩编程，回复：加群，添加马哥微信（备注：12306）获取项目资料
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class AliPayNativeHandler extends AbstractPayHandler implements AbstractExecuteStrategy<PayRequest, PayResponse> {



    @Override
    public PayResponse pay(PayRequest payRequest) {
             log.info(JSON.toJSONString(payRequest));
            return new PayResponse(StrUtil.replace(StrUtil.replace("OK", "\"", "'"), "\n", ""));

    }

    @Override
    public String mark() {
        return StrBuilder.create()
                .append(PayChannelEnum.ALI_PAY.name())
                .append("_")
                .append(PayTradeTypeEnum.NATIVE.name())
                .toString();
    }

    @Override
    public PayResponse executeResp(PayRequest requestParam) {
        return pay(requestParam);
    }
}
